package com.tools.s7.network.listener;

import com.google.gson.internal.$Gson$Types;
import com.tools.s7.network.exception.ExceptionHandle;
import com.tools.s7.network.exception.ResponeThrowable;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public abstract class OnRequestListener<T> {

    public Type tClass;
    public OnRequestListener() {
        tClass = getSuperclassTypeParameter(getClass());
    }

    static Type getSuperclassTypeParameter(Class<?> subclass) {
        Type superclass = subclass.getGenericSuperclass();
        if (superclass instanceof Class) {
//            throw new RuntimeException("Missing type parameter.");
            return Object.class;
        }
        ParameterizedType parameterized = (ParameterizedType) superclass;
        return $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[0]);
    }

    public abstract void onSuccess(T data);

    public abstract void onError(ResponeThrowable error);
}
